package com.budwk.app.enterprise.controllers.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.domain.vo.IncomeStatementVo;
import com.budwk.app.enterprise.services.IncomeStatementBaseService;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

@IocBean
@At("/platform/enterprise/income/statement/baseinfo")
@ApiDefinition(tag = "利润详情表")
@Slf4j
public class IncomeStatementBaseController {
    @Inject
    private IncomeStatementBaseService incomeStatementBaseinfoService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "分页查询利润详情表")
    @ApiFormParams(implementation = IncomeStatementVo.class)
    @ApiResponses(
    implementation = IncomeStatementVo.class)
    @SaCheckPermission("enterprise.income.statement.baseinfo.listByPage")
    public Result<?> list(@Param("..") IncomeStatementVo bean) {
        log.info("IncomeStatementBaseController listpage param: {}", JSONObject.toJSONString(bean));
        Pagination pagination = incomeStatementBaseinfoService.listByPage(bean);
        return Result.data(pagination);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "新增利润详情表")
    @ApiFormParams(implementation = IncomeStatementVo.class)
    @ApiResponses
    @SLog(tag = "新增利润详情表", value = "${args[0].id}")
    @SaCheckPermission("enterprise.income.statement.baseinfo.create")
    public Result<?> create(@Param("..") IncomeStatementVo statementVo) {
        log.info("IncomeStatementBaseController create param: {}", JSONObject.toJSONString(statementVo));
        return Result.data(incomeStatementBaseinfoService.create(statementVo));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "修改利润详情表")
    @ApiFormParams(
        implementation = IncomeStatementVo.class
    )
    @ApiResponses
    @SLog(tag = "修改利润详情表", value = "${args[0].id}")
    @SaCheckPermission("enterprise.income.statement.baseinfo.update")
    public Result<?> update(@Param("..") IncomeStatementVo statementVo) {
        log.info("IncomeStatementBaseController update param: {}", JSONObject.toJSONString(statementVo));
        return Result.data(incomeStatementBaseinfoService.updateData(statementVo));
    }

    @At("/get")
    @Ok("json")
    @POST
    @ApiOperation(name = "获取利润详情表")
    @ApiFormParams(
        {
            @ApiFormParam(name = "id", description = "唯一标识",required = true, check = true)
        }
    )
    @SaCheckPermission("enterprise.income.statement.baseinfo.getData")
    public Result<?> getData(@Param("id")String id) {
        log.info("IncomeStatementBaseController getData param: {}", id);
        return Result.data(incomeStatementBaseinfoService.getData(id));
    }

    @At("/delete")
    @Ok("json")
    @POST
    @ApiOperation(name = "删除利润详情表")
    @ApiFormParams(
        {
            @ApiFormParam(name = "id", description = "唯一标识",required = true, check = true)
        }
    )
    @SLog(tag = "删除利润详情表", value = "${args[0]}")
    @SaCheckPermission("enterprise.income.statement.baseinfo.delete")
    public Result<?> delete(@Param("id")String id) {
        log.info("IncomeStatementBaseController deleteById param: {}, userName: {}", id, SecurityUtil.getUserUsername());
        incomeStatementBaseinfoService.deleteById(id);
        return Result.success();
    }
}
